package ljl.alg.wangzheng_camp.round1.hashmap;

import commons.ListNode;

import java.util.HashSet;
import java.util.Set;

public class _02_01_remove_duplicate_node {
    
    /*
    * 怎么感觉一个 hashmap 就搞定了
    * */
    public ListNode removeDuplicateNodes(ListNode head) {
        Set<Integer> vals = new HashSet<>();
        ListNode dummy = new ListNode();
        ListNode p = dummy;
        ListNode cur = head;
        while (cur != null) {
            if (!vals.contains(cur.val)) {
                p.next = cur;
                p = p.next;
                vals.add(cur.val);
            }
            cur = cur.next;
        }
        // 忘了断开了最后
        p.next = null;
        return dummy.next;
    }
    
}
